<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>box</div>
    <div>box</div>
    <ul>
        <li>1</li>
        <li class="li1">3</li>
    </ul>
    <script>
        var div = document.createElement('div');
        div.className = 'box1'
        div.innerHTML = 'box1'
        document.body.appendChild(div)
        
        var li = document.createElement('li')
        li.innerHTML = 2
        li.className = 'li2'
        var ul = document.querySelector('ul')
        var last = document.querySelector('.li1')
        
        ul.insertBefore(li,last)

        
    </script>
</body>
</html>